package com.gomtel.smartdevice.ui.activity.tools;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.base.WatchAppBaseActivity;
import com.gomtel.smartdevice.moudle.event.CommonEvent;
import com.gomtel.smartdevice.moudle.event.EventCode;
import com.gomtel.smartdevice.server.SingBaiDuService;
import com.gomtel.smartdevice.ui.activity.MultiTypeActivity;
import com.gomtel.smartdevice.ui.adapter.TabPageIndicatorAdapter;
import com.gomtel.smartdevice.ui.fragment.PedometerDayFragemnt;
import com.gomtel.smartdevice.ui.fragment.PedometerMonthFragemnt;
import com.gomtel.smartdevice.ui.fragment.PedometerWeekFragemnt;
import com.gomtel.smartdevice.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/5/22 0022.
 * 计步显示
 */

public class PedometerActivity extends WatchAppBaseActivity implements View.OnClickListener, TabLayout.OnTabSelectedListener {

    @BindView(R.id.view_page)
    ViewPager view_page;
    @BindView(R.id.tab_layout)
    TabLayout tab_layout;
    @BindView(R.id.title_name)
    TextView title_name;
    @BindView(R.id.img_btn_black)
    ImageButton img_btn_black;
    @BindView(R.id.life)
    TextView life;
    @BindView(R.id.right)
    TextView right;
    private TabPageIndicatorAdapter tabPageIndicatorAdapter;
    private List<Fragment> mFragments = new ArrayList<>();
    private String[] TITLE;
    private Intent singBaiDuService;

    @Override
    protected void registerEvent(CommonEvent commonevent) {

    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_pedometer;
    }

    @Override
    protected void initClass() {
        mFragments.add(new PedometerDayFragemnt());
        mFragments.add(new PedometerWeekFragemnt());
        mFragments.add(new PedometerMonthFragemnt());
        singBaiDuService = new Intent(this, SingBaiDuService.class);
        startService(singBaiDuService);
    }

    @Override
    protected void initData() {
        TITLE = new String[]{getString(R.string.day), getString(R.string.week), getString(R.string.month)};
    }

    @Override
    protected void initView() {
        title_name.setText(getString(R.string.pedometer));
        tabPageIndicatorAdapter = new TabPageIndicatorAdapter(getSupportFragmentManager(), TITLE, (ArrayList<Fragment>) mFragments);
        view_page.setAdapter(tabPageIndicatorAdapter);
        tab_layout.setupWithViewPager(view_page);
        tab_layout.post(new Runnable() {
            @Override
            public void run() {
                CommonUtils.setIndicator(tab_layout, 15, 15);
            }
        });
    }

    @Override
    protected void initListener() {
        tab_layout.setOnTabSelectedListener(this);
        img_btn_black.setOnClickListener(this);
        life.setOnClickListener(this);
        right.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_btn_black:
                finish();
                break;
            case R.id.life:
                Intent intent = new Intent(this, MultiTypeActivity.class);
                intent.putExtra("ActionType", String.valueOf(EventCode.CALORY));
                startActivity(intent);
                break;
            case R.id.right:
                startActivity(new Intent(this, LocationActivity.class));
                break;
        }
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        view_page.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        stopService(singBaiDuService);
    }
}
